package com.helome.netty.Discard;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.*;

/**
 * discard server handler
 * Created by bin.liu on 14-5-24.
 */
public class DiscardServerHandler extends SimpleChannelHandler {

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        /*ChannelBuffer channelBuffer = (ChannelBuffer) e.getMessage();
        if  (channelBuffer.readable()) {
            System.out.println((char)channelBuffer.readByte());
            System.out.flush();
        }*/
        Channel channel = e.getChannel();
        channel.write(e.getMessage());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
        e.getCause().printStackTrace();
        Channel channel = e.getChannel();
        channel.close();
    }
}
